package com.corpgovernment.organization.mq;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.corpgovernment.api.messageadvice.enums.MsgBizType;
import com.corpgovernment.api.organization.enums.UserOrgRelationStatusEnum;
import com.corpgovernment.api.organization.model.user.NameInfoBo;
import com.corpgovernment.api.organization.vo.TransferEmployeeOrgInfoVo;
import com.corpgovernment.common.apollo.OrganizationApollo;
import com.corpgovernment.common.enums.NationalityEnum;
import com.corpgovernment.common.mq.consumer.AbstractMultiTenantRocketMQConsumer;
import com.corpgovernment.common.mq.enums.MessageBizTypeEnum;
import com.corpgovernment.common.utils.ABTestUtil;
import com.corpgovernment.common.utils.Md5Util;
import com.corpgovernment.job.dao.entity.db.EmployeeJobRelationDo;
import com.corpgovernment.job.dao.mapper.EmployeeJobRelationMapper;
import com.corpgovernment.organization.Bo.SyncEmployeeInfoMQBo;
import com.corpgovernment.organization.constant.CommonConst;
import com.corpgovernment.organization.dataloader.db.MbOrgEmployeeLoader;
import com.corpgovernment.organization.entity.db.*;
import com.corpgovernment.organization.model.OpenCardEmployeeModel;
import com.corpgovernment.organization.model.SupplierCompanyModel;
import com.corpgovernment.organization.service.*;
import com.corpgovernment.organization.service.impl.FreshPassengerRelationServiceImpl;
import com.corpgovernment.organization.util.StrUtils;
import com.ctrip.corp.obt.generic.core.context.TenantContext;
import com.ctrip.corp.obt.generic.core.context.TraceContext;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.DateUtils;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.*;
import java.util.stream.Collectors;

@Component
@Slf4j
public class SyncEmployeeInfoMQConsumer extends AbstractMultiTenantRocketMQConsumer {

    @Autowired
    private MbOrgEmployeeLoader mbOrgEmployeeLoader;
    @Autowired
    private IOrganizationEmployeeService organizationEmployeeService;
    @Autowired
    private IUserLoginService userLoginService;
    @Autowired
    private IFreshPassengerService freshPassengerService;
    @Autowired
    private FreshPassengerRelationServiceImpl freshPassengerRelationService;
    @Autowired
    private IUserOrgRelationService userOrgRelationService;
    @Autowired
    private IOrganizationInfoService organizationInfoService;
    @Autowired
    private IOrgUserIdCardService orgUserIdCardService;
    @Autowired
    private BookingRelationService bookingRelationService;
    @Autowired
    private RedemptionCodeService redemptionCodeService;
    @Autowired
    private ABTestUtil abTestUtil;
    @Autowired
    private MsgService msgService;
    @Resource
    private EmployeeJobRelationMapper employeeJobRelationMapper;
    @Autowired
    private CtripOpenCardService ctripOpenCardService;
    @Autowired
    private OrganizationApollo organizationApollo;

    private final static String OpenApi_Action_Status_1 = "1";
    private final static String OpenApi_Action_Status_2 = "2";
    private final static String OpenApi_Action_Status_3 = "3";
    private final static String OpenApi_Action_Status_4 = "4";

    @Override
    protected void consume(MessageExt messageExt, ConsumeConcurrentlyContext context) {
        try {
            if(StringUtils.isBlank(TraceContext.getRequestId())) {
                TraceContext.setRequestId(UUID.randomUUID().toString());
            }
            // 获取消息内容
            String msg = new String(messageExt.getBody(), StandardCharsets.UTF_8);
            log.info("[MsgId[{}]，SyncEmployeeInfoMQConsumer]接受到的消息[{}]", messageExt.getMsgId(), msg);

            SyncEmployeeInfoMQBo syncEmployeeInfoMQBo = JsonUtils.parse(msg, SyncEmployeeInfoMQBo.class);

            process(syncEmployeeInfoMQBo);
        } catch (Exception ex) {
            log.error("SyncEmployeeInfoMQConsumer.consume", ex);
        }
    }

    public void process(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo){
        switch (syncEmployeeInfoMQBo.getActionType()){
            case "add":
                add(syncEmployeeInfoMQBo);
                break;
            case "update":
                update(syncEmployeeInfoMQBo);
                break;
            case "delete":
                delete(syncEmployeeInfoMQBo);
                break;
            case "transfer":
                transfer(syncEmployeeInfoMQBo);
                break;
        }
        // 自动开卡开关
        String syncEmployeeAndOpenCard = organizationApollo.getSyncEmployeeAndOpenCard();
        log.info("自动开卡开关,syncEmployeeAndOpenCard:{}",syncEmployeeAndOpenCard);
        if("true".equalsIgnoreCase(syncEmployeeAndOpenCard)){
            this.syncEmployeeAndOpenCard(syncEmployeeInfoMQBo);
        }
    }

    /**
     * 自动开卡
     * @param syncEmployeeInfoMQBo
     */
    private void syncEmployeeAndOpenCard(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo) {
        log.info("自动开卡,syncEmployeeInfoMQBo:{}",JsonUtils.toJsonString(syncEmployeeInfoMQBo));
        // 人员信息同步完成,进行自动开卡
        if(ObjectUtil.isEmpty(syncEmployeeInfoMQBo.getBasicInfo())){
            log.info("自动开卡,人员信息为空,{}",JsonUtils.toJsonString(syncEmployeeInfoMQBo));
            return;
        }
        String orgId = syncEmployeeInfoMQBo.getBasicInfo().getOrgId();
        List<SupplierCompanyModel> companyConfigList = ctripOpenCardService.getParentConfig(orgId);
        log.info("获取企业订购业务配置,companyConfigList:{}",JsonUtils.toJsonString(companyConfigList));
        // 获取开启一人一卡的配置
        if(CollectionUtils.isNotEmpty(companyConfigList)){
            companyConfigList = companyConfigList.stream().filter( x->x.getOpenCardType().equals("X")).collect(Collectors.toList());
        }
        log.info("获取开启一人一卡的配置,companyConfigList:{}",JsonUtils.toJsonString(companyConfigList));
        if (CollectionUtils.isEmpty(companyConfigList) || StringUtils.isBlank(companyConfigList.get(0).getSubAccountCode())){
            log.info("订购携程商旅产线业务&&一人一卡错误,{}",JsonUtils.toJsonString(syncEmployeeInfoMQBo));
            return;
        }
        OpenCardEmployeeModel model = convertOpenCardEmployee(syncEmployeeInfoMQBo);
        // 开始开卡
        log.info("开始开卡,openCard,orgId:{},model:{}",orgId,JsonUtils.toJsonString(model));
        List<OpenCardEmployeeModel> failedList = ctripOpenCardService.openCard(orgId, Collections.singletonList(model), null);
        if(CollectionUtils.isNotEmpty(failedList)){
            log.info("自动开卡,失败,failedList:{}",JsonUtils.toJsonString(failedList));
        }
    }

    private static OpenCardEmployeeModel convertOpenCardEmployee(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo) {
        SyncEmployeeInfoMQBo.BasicInfo basicInfo = syncEmployeeInfoMQBo.getBasicInfo();
        OpenCardEmployeeModel model = new OpenCardEmployeeModel();
        model.setAreaCode(basicInfo.getCountryCode());
        model.setEmail(basicInfo.getEmail());
        model.setName(basicInfo.getName());
        model.setGender(basicInfo.getGender());
        model.setNationality(basicInfo.getNationality());
        model.setBirthday(StrUtil.isNotBlank(basicInfo.getBirthday())?
                cn.hutool.core.date.DateUtil.parseDate(basicInfo.getBirthday()):
                null);
        model.setUid(basicInfo.getUid());
        model.setMobilePhone(basicInfo.getMobilePhone());
        return model;
    }

    public void add(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo){
        log.info("SyncEmployeeInfoMQConsumer.add:{}", JsonUtils.toJsonString(syncEmployeeInfoMQBo));
        SyncEmployeeInfoMQBo.BasicInfo basicInfo = syncEmployeeInfoMQBo.getBasicInfo();
        List<SyncEmployeeInfoMQBo.CardType> cardTypeList = syncEmployeeInfoMQBo.getCardTypeList();
        //加密前的密码
        String pwd = buildNewPwd(basicInfo.getMobilePhone());
        //登录信息
        MbUserLogin mbUserLogin = this.getMbUserLogin(basicInfo,pwd);
        //用户信息
        MbOrgEmployeeInfo mbOrgEmployeeInfo = this.getMbOrgEmployeeInfo(basicInfo);
        //组织人员关联
        MbUserOrgRelation mbUserOrgRelation = this.getMbUserOrgRelation(basicInfo);
        //新鲜度
        MbFreshPassenger mbFreshPassenger = this.getMbFreshPassenger(basicInfo);
        //新鲜度关联
        MbFreshPassengerRelation mbFreshPassengerRelation = this.getMbFreshPassengerRelation(basicInfo);
        //证件号
        List<MbOrgUserIdcard> mbOrgUserIdCardList = this.getMbOrgUserIdCardList(basicInfo, cardTypeList);
        log.info("mbUserLogin={},mbOrgEmployeeInfo={},mbUserOrgRelation={},mbFreshPassenger={},mbFreshPassengerRelation={},mbOrgUserIdCardList={}",
                JsonUtils.toJsonString(mbUserLogin),JsonUtils.toJsonString(mbOrgEmployeeInfo),JsonUtils.toJsonString(mbUserOrgRelation),
                JsonUtils.toJsonString(mbFreshPassenger),JsonUtils.toJsonString(mbFreshPassengerRelation),JsonUtils.toJsonString(mbOrgUserIdCardList));
        //1.修改登录表 + 发送验证码
        createLoginUserAndSendSms(pwd, mbUserLogin);
        //2.修改员工信息表
        mbOrgEmployeeLoader.create(mbOrgEmployeeInfo);
        // 绑定兑换码
        redemptionCodeService.bindRedemptionCode(mbOrgEmployeeInfo.getUid(), mbOrgEmployeeInfo.getName());
        //3.插入人员组织表
        userOrgRelationService.save(mbUserOrgRelation);
        //4.插入新鲜度表
        freshPassengerService.save(mbFreshPassenger);
        //5.插入新鲜度关联表
        freshPassengerRelationService.save(mbFreshPassengerRelation);
        //6.插入证件信息
        orgUserIdCardService.insertList(mbOrgUserIdCardList);
        // 岗位信息
        employeeJobRelationMapper.createOrUpdate(new EmployeeJobRelationDo(basicInfo.getUid(), basicInfo.getJobId()));
    }

    private void createLoginUserAndSendSms(String pwd, MbUserLogin mbUserLogin) {
        userLoginService.create(mbUserLogin);
        // 发送短信
        Boolean avalibleSendMsg =  abTestUtil.getBooleanAbTestResultWithAuto("sendSms", TenantContext.getTenantId());
        if (avalibleSendMsg) {
            Map<String, Object> vars = new HashMap<>();
            vars.put("phone", mbUserLogin.getPhoneNum());
            vars.put("pwd", pwd);
            msgService.sendAliyunTemplateMsg(MsgBizType.EMPLOYEE_INIT_PHONE_AND_PWD,vars, mbUserLogin.getPhoneNum(), mbUserLogin.getCountryCode());
        }
    }

    public void update(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo){
        log.info("SyncEmployeeInfoMQConsumer.update:{}", JsonUtils.toJsonString(syncEmployeeInfoMQBo));
        SyncEmployeeInfoMQBo.BasicInfo basicInfo = syncEmployeeInfoMQBo.getBasicInfo();
        List<SyncEmployeeInfoMQBo.CardType> cardTypeList = syncEmployeeInfoMQBo.getCardTypeList();

        //加密前的密码
        String pwd = buildNewPwd(basicInfo.getMobilePhone());
        //登录信息
        MbUserLogin mbUserLogin = this.getMbUserLogin(basicInfo,pwd);
        //用户信息
        MbOrgEmployeeInfo mbOrgEmployeeInfo = this.getMbOrgEmployeeInfo(basicInfo);
        //组织人员关联
        MbUserOrgRelation mbUserOrgRelation = this.getMbUserOrgRelation(basicInfo);
        //新鲜度
        MbFreshPassenger mbFreshPassenger = this.getMbFreshPassenger(basicInfo);
        //新鲜度关联
        MbFreshPassengerRelation mbFreshPassengerRelation = this.getMbFreshPassengerRelation(basicInfo);
        //证件号
        List<MbOrgUserIdcard> mbOrgUserIdCardList = this.getMbOrgUserIdCardList(basicInfo, cardTypeList);

        //1.修改登录表 + 发送验证码
        if(basicInfo.getIsSyncLoginPhone()){
            updateLoginUserAndSendSms(pwd, mbUserLogin);
        }
        //2.修改员工信息表
        mbOrgEmployeeLoader.updateALLByUid(mbOrgEmployeeInfo);
        //3.修改人员组织表
        List<MbUserOrgRelation> userOrgRelationList = userOrgRelationService.findByUid(mbUserOrgRelation.getUid());
        userOrgRelationService.updateByRecord(mbUserOrgRelation);
        //新的orgId与库表中不一样
        Optional<MbUserOrgRelation> firstOrgRelation = userOrgRelationList.stream().filter(item -> basicInfo.getOrgId().equals(item.getOrgId())).findFirst();
        if (!firstOrgRelation.isPresent()){
            MbUserOrgRelation userOrgRelation = userOrgRelationList.get(0);
            basicInfo.setOldOrgId(userOrgRelation.getOrgId());
            transfer(syncEmployeeInfoMQBo);
            return;
        }

        //4.修改新鲜度表
        if (Objects.nonNull(mbFreshPassenger)){
            freshPassengerService.updateALLByRecord(mbFreshPassenger);
        }
        //5.修改新鲜度关联表
        if (Objects.nonNull(mbFreshPassengerRelation)){
            List<MbFreshPassengerRelation> mbFreshPassengerRelations = freshPassengerRelationService.selectByUid(mbFreshPassengerRelation.getUid());
            if (CollectionUtils.isEmpty(mbFreshPassengerRelations)){
                freshPassengerRelationService.save(mbFreshPassengerRelation);
            }
        }
        //6.修改证件信息
        if (Objects.nonNull(mbOrgUserIdCardList)){
            orgUserIdCardService.deleteByUids(Optional.ofNullable(mbOrgUserIdCardList).orElse(Collections.emptyList()).stream().map(item -> item.getEmployeeUid()).collect(Collectors.toList()));
            orgUserIdCardService.insertList(mbOrgUserIdCardList);
        }
        // 岗位信息
        if (basicInfo.getJobId() == null) {
            employeeJobRelationMapper.removeByUid(basicInfo.getUid());
        } else {
            employeeJobRelationMapper.createOrUpdate(new EmployeeJobRelationDo(basicInfo.getUid(), basicInfo.getJobId()));
        }
    }

    private void updateLoginUserAndSendSms(String pwd, MbUserLogin mbUserLogin) {
        userLoginService.updateByUid(mbUserLogin);
        // 发送短信
        Boolean avalibleSendMsg =  abTestUtil.getBooleanAbTestResultWithAuto("sendSms", TenantContext.getTenantId());
        if (avalibleSendMsg) {
            Map<String, Object> vars = new HashMap<>();
            vars.put("phone", mbUserLogin.getPhoneNum());
            vars.put("pwd", pwd);
            msgService.sendAliyunTemplateMsg(MsgBizType.EMPLOYEE_RESET_PHONE_AND_PWD,vars, mbUserLogin.getPhoneNum(), mbUserLogin.getCountryCode());
        }
    }

    public void delete(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo){
        log.info("SyncEmployeeInfoMQConsumer.delete:{}", JsonUtils.toJsonString(syncEmployeeInfoMQBo));
        SyncEmployeeInfoMQBo.BasicInfo basicInfo = syncEmployeeInfoMQBo.getBasicInfo();
        userOrgRelationService.deleteAllByUid(basicInfo.getUid(), basicInfo.getOrgId());
    }

    public void transfer(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo){
        log.info("SyncEmployeeInfoMQConsumer.transfer:{}", JsonUtils.toJsonString(syncEmployeeInfoMQBo));
        if(Objects.equals(syncEmployeeInfoMQBo.getBasicInfo().getOldOrgId(), syncEmployeeInfoMQBo.getBasicInfo().getOrgId())){
            return;
        }
        SyncEmployeeInfoMQBo.BasicInfo basicInfo = syncEmployeeInfoMQBo.getBasicInfo();
        TransferEmployeeOrgInfoVo transferEmployeeOrgInfoVo = new TransferEmployeeOrgInfoVo();
        transferEmployeeOrgInfoVo.setNewOrgId(basicInfo.getOrgId());
        TransferEmployeeOrgInfoVo.EmployeeOrgInfo employeeOrgInfo = new TransferEmployeeOrgInfoVo.EmployeeOrgInfo();
        employeeOrgInfo.setOldOrgId(basicInfo.getOldOrgId());
        employeeOrgInfo.setUid(basicInfo.getUid());
        employeeOrgInfo.setPostId(syncEmployeeInfoMQBo.getBasicInfo().getPostId());
        transferEmployeeOrgInfoVo.setEmployeeOrgInfoList(CollectionUtils.newArrayList(employeeOrgInfo));
        organizationInfoService.batchTransferEmployeeOrgInfo(transferEmployeeOrgInfoVo);
    }

    public MbUserLogin getMbUserLogin(SyncEmployeeInfoMQBo.BasicInfo basicInfo,String pwd){
        MbUserLogin mbUserLogin = new MbUserLogin();
        mbUserLogin.setAccountName(basicInfo.getCountryCode() + basicInfo.getMobilePhone());
        mbUserLogin.setUid(basicInfo.getUid());
        mbUserLogin.setPwd(Md5Util.getDeepMd5Msg(basicInfo.getUid(), pwd));
        mbUserLogin.setUserName(basicInfo.getName());
        mbUserLogin.setBgUser(0);
        mbUserLogin.setCountryCode(basicInfo.getCountryCode());
        mbUserLogin.setPhoneNum(basicInfo.getMobilePhone());
        mbUserLogin.setEmail(basicInfo.getEmail());
        mbUserLogin.setStatus(OpenApi_Action_Status_1.equals(basicInfo.getStatus()) ? 1 : 0);
        return mbUserLogin;
    }

    private String buildNewPwd(String phoneNum) {
        String newLast5 = phoneNum.substring(phoneNum.length() - 5);
        // 生成包含字母的随机数
        SecureRandom random = new SecureRandom();
        byte[] bytes = new byte[4];
        random.nextBytes(bytes);
        String randomStr = Base64.getEncoder().encodeToString(bytes).substring(0, 4);
        return newLast5 + randomStr;
    }

    public MbOrgEmployeeInfo getMbOrgEmployeeInfo(SyncEmployeeInfoMQBo.BasicInfo basicInfo){
        MbOrgEmployeeInfo mbOrgEmployeeInfo = new MbOrgEmployeeInfo();
        mbOrgEmployeeInfo.setUid(basicInfo.getUid());
        mbOrgEmployeeInfo.setName(basicInfo.getName());
        mbOrgEmployeeInfo.setValid(CommonConst.TRUE);
        mbOrgEmployeeInfo.setMobilePhone(basicInfo.getMobilePhone());
        mbOrgEmployeeInfo.setAreaCode(basicInfo.getCountryCode());
        mbOrgEmployeeInfo.setEmail(basicInfo.getEmail());
        mbOrgEmployeeInfo.setGender(basicInfo.getGender());
        mbOrgEmployeeInfo.setBirthday(StringUtils.isBlank(basicInfo.getBirthday()) ? null : DateUtils.parse(basicInfo.getBirthday(), "yyyy-MM-dd"));
        mbOrgEmployeeInfo.setNationality(
                Objects.nonNull(
                        NationalityEnum.getByCode(basicInfo.getNationality())
                ) ? String.format("%s|%s", basicInfo.getNationality(), NationalityEnum.getByCode(basicInfo.getNationality()).getDesc()) : String.format("%s|%s", NationalityEnum.CN.getCode(), NationalityEnum.CN.getDesc()));
        mbOrgEmployeeInfo.setIsBackground(Boolean.FALSE);
        mbOrgEmployeeInfo.setDeleteTime(new Date(0));
        mbOrgEmployeeInfo.setDatachangeCreatetime(new Date());
        mbOrgEmployeeInfo.setDatachangeLasttime(new Date());
        mbOrgEmployeeInfo.setEmployeeType(basicInfo.getEmployeeType());
        NameInfoBo nameInfoBo = new NameInfoBo();
        nameInfoBo.setFullName(basicInfo.getName());
        nameInfoBo.setNationality(basicInfo.getNationality());
        if(StrUtils.checkNameInfo(nameInfoBo)){
            mbOrgEmployeeInfo.setNameInfo(JsonUtils.toJsonString(nameInfoBo));
        }
        return mbOrgEmployeeInfo;
    }

    public MbUserOrgRelation getMbUserOrgRelation(SyncEmployeeInfoMQBo.BasicInfo basicInfo){
        MbUserOrgRelation mbUserOrgRelation = new MbUserOrgRelation();
        mbUserOrgRelation.setUid(basicInfo.getUid());
        mbUserOrgRelation.setOrgId(basicInfo.getOrgId());
        mbUserOrgRelation.setManageUid(basicInfo.getManageUid());
        if (OpenApi_Action_Status_3.equals(basicInfo.getStatus())){
            mbUserOrgRelation.setStatus(UserOrgRelationStatusEnum.LEAVE.getStatus());
        } else {
            mbUserOrgRelation.setStatus(UserOrgRelationStatusEnum.NORMAL.getStatus());
        }
        mbUserOrgRelation.setDeleteTime(new Date(0));
        mbUserOrgRelation.setDatachangeCreatetime(new Date());
        mbUserOrgRelation.setDatachangeLasttime(new Date());
        mbUserOrgRelation.setIsLeader(0);
        mbUserOrgRelation.setPostId(basicInfo.getPostId());
        return mbUserOrgRelation;
    }

    public MbFreshPassenger getMbFreshPassenger(SyncEmployeeInfoMQBo.BasicInfo basicInfo){
        MbFreshPassenger mbFreshPassenger = new MbFreshPassenger();
        mbFreshPassenger.setEmployeeUid(basicInfo.getUid());
        mbFreshPassenger.setOrgId(basicInfo.getOrgId());
        mbFreshPassenger.setName(basicInfo.getName());
        mbFreshPassenger.setValid(Boolean.FALSE);
        mbFreshPassenger.setIsDeleted(Boolean.FALSE);
        mbFreshPassenger.setDatachangeLasttime(new Date());
        mbFreshPassenger.setDatachangeCreatetime(new Date());
        mbFreshPassenger.setFreshTime(new Date());
        return mbFreshPassenger;
    }

    public MbFreshPassengerRelation getMbFreshPassengerRelation(SyncEmployeeInfoMQBo.BasicInfo basicInfo){
        MbFreshPassengerRelation mbFreshPassengerRelation = new MbFreshPassengerRelation();
        mbFreshPassengerRelation.setEmployeeFlag(1);
        mbFreshPassengerRelation.setFreshUid(basicInfo.getUid());
        mbFreshPassengerRelation.setUid(basicInfo.getUid());
        mbFreshPassengerRelation.setFreshTime(new Date());
        mbFreshPassengerRelation.setIsDeleted(Boolean.FALSE);
        mbFreshPassengerRelation.setDatachangeLasttime(new Date());
        mbFreshPassengerRelation.setDatachangeCreatetime(new Date());
        return mbFreshPassengerRelation;
    }

    public List<MbOrgUserIdcard> getMbOrgUserIdCardList(SyncEmployeeInfoMQBo.BasicInfo basicInfo, List<SyncEmployeeInfoMQBo.CardType> cardTypeList){
        if (CollectionUtils.isEmpty(cardTypeList)){
            return Collections.emptyList();
        }
        List<MbOrgUserIdcard> mbOrgUserIdCardList = new ArrayList<>();
        for (SyncEmployeeInfoMQBo.CardType cardType: cardTypeList){
            MbOrgUserIdcard mbOrgUserIdcard = new MbOrgUserIdcard();
            mbOrgUserIdcard.setEmployeeUid(basicInfo.getUid());
            mbOrgUserIdcard.setCardType(Integer.valueOf(cardType.getCardType()));
            mbOrgUserIdcard.setCardNo(cardType.getCardNo());
            mbOrgUserIdcard.setTimeLimit(Optional.ofNullable(cardType.getTimeLimit()).map(item -> DateUtil.parse(item, "yyyy-MM-dd")).orElse(null));
            mbOrgUserIdcard.setDeleteTime(new Date(0));
            mbOrgUserIdcard.setDatachangeCreatetime(new Date());
            mbOrgUserIdcard.setDatachangeLasttime(new Date());
            mbOrgUserIdCardList.add(mbOrgUserIdcard);
        }
        return mbOrgUserIdCardList;
    }

    @Override
    protected MessageBizTypeEnum getMessageBizType() {
        return MessageBizTypeEnum.SYNC_EMPLOYEE_INFO;
    }

}
